/*----------------------------------------------------------------------
  - File name      : STC8Ax_TIMER.h
  - Author         : Quark Team
  - Update date    : 2020-12-09                  
  -	Copyright      : Gevico Electronic studio   
  - Module comments: Header file of STC8Ax_TIMER module.
-----------------------------------------------------------------------*/
#ifndef __STC8Ax_TIMER_H_
#define __STC8Ax_TIMER_H_
/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/
/*--------------------------------------------------------
| @Description: STC8Ax Options                           |
--------------------------------------------------------*/
#include "STC8Ax_REG.h"   
/*--------------------------------------------------------
| @Description: STC8Ax core                              |
--------------------------------------------------------*/
#include "STC8Ax_CORE.h"
/*-----------------------------------------------------------------------
|                                 DATA                                  |
-----------------------------------------------------------------------*/
/*--------------------------------------------------------
| @Description: System clock frequency                   |
--------------------------------------------------------*/
extern uint32 SYSCLK_FRE;
/*--------------------------------------------------------
| @Description: TIMER number                             |
--------------------------------------------------------*/
/*
TIMER0: 16 Bit timer has four working modes
TIMER1: Same as timer 0, but invalid in 16 bit auto reload 
        mode without maskable interrupt, stop counting
TIMER2: The working mode is fixed in 16 bit auto reload mode
TIMER3: The working mode is fixed in 16 bit auto reload mode
TIMER4: The working mode is fixed in 16 bit auto reload mode
*/
/*--------------------------------------------------------
| @Description: TIMER type                               |
--------------------------------------------------------*/
typedef enum
{
  TIMER_Type_Timer = 0, TIMER_Type_Counter
} TIMERType_Type;
/*--------------------------------------------------------
| @Description: TIMER mode enum                          |
--------------------------------------------------------*/
/*
Mode 0: 16 Bit auto reload timer
Mode 1: 16 Bit non auto reload timer
Mode 2:  8 Bit auto reload timer
Mode 3: 16 Bit auto reload non maskable interrupt
*/
typedef enum
{
	TIMER_16BitAutoReload = 0  , 
	TIMER_16Bit                , 
	TIMER_8BitAutoReload       , 
	TIMER_16BitAutoReloadNoMask  
}	TIMERMode_Type;

/*--------------------------------------------------------
| @Description: TIME Clock mode enum                     |
--------------------------------------------------------*/
/*
Timing 12t mode: The machine executes 12 cycles
Timing  1t mode: The machine executes 1 cycles
*/
typedef enum
{
	TIMER_TCY_12T = 0x00,  
	TIMER_TCY_1T  = 0x01,	 
}	TIMERTCycle_Type;

/*--------------------------------------------------------
| @Description: TIME Init structure                      |
--------------------------------------------------------*/
typedef struct 
{
  TIMERType_Type Type;       //timer type
  TIMERMode_Type Mode;       //Working mode
  TIMERTCycle_Type TCycle;   //Instruction cycle
  FUNSTATE ClkOut;           //Programmable clock output
  uint16 Value;              //Loading initial value
  FUNSTATE Run;              //Operation control bit
} TIMER_InitType;

/*-----------------------------------------------------------------------
|                             API FUNCTION                              |
-----------------------------------------------------------------------*/

/*--------------------------------------------------------
| @Description: TIMER5 peripheral Drivice function       |
--------------------------------------------------------*/

FSCSTATE TIMER5_Wake_Up_Power(uint16 Value,FUNSTATE State);

/*--------------------------------------------------------
| @Description: TIMER peripheral init function           |
--------------------------------------------------------*/

FSCSTATE TIMER0_Init(const TIMER_InitType *TIMERx);
FSCSTATE TIMER1_Init(const TIMER_InitType *TIMERx);
FSCSTATE TIMER2_Init(const TIMER_InitType *TIMERx);
FSCSTATE TIMER3_Init(const TIMER_InitType *TIMERx);
FSCSTATE TIMER4_Init(const TIMER_InitType *TIMERx);

#endif
/*-----------------------------------------------------------------------
|          END OF FLIE        (C) COPYRIGHT Gevico Electronics          | 
-----------------------------------------------------------------------*/

